<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3/jquery.min.js"></script>
<script  type="text/javascript">
function searchKeyPress(e)
{	
	// look for window.event in case event isn't passed in
	
	if (typeof e == 'undefined' && window.event) { e = window.event; }
	if (e.keyCode == 13)
	{
		document.getElementById('sendBtn').click();
	}
}
function submitForm(){
		$.ajax({
			type     : "POST",
			cache    : false,
			url      : 'add_messages.php',
			data     : $('#chatFrm').serialize(),
			success  : function(data) {
				viewMessages();
				$('#message').val(''); // clear textarea
			}
		});	
		
}

function viewMessages(){
	$.ajax({
			type     : "GET",
			cache    : false,
			url      : 'view_messages.php',
			data     : '',
			success  : function(data) {
				$('#msgDiv').html(data); // write messages in textarea
				setTimeout(viewMessages, 5000);
			}
	});	
	
}
setTimeout(viewMessages, 5000);


</script>